<!DOCTYPE html>
<#assign ctx=springMacroRequestContext.contextPath />
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>任务日志</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        layui.use(['form', 'table'], function() {
            var form = layui.form,
                table = layui.table,
                jobInfoId = '${jobInfoId}';
            // 初始化表格
            table.render({
                elem: '#currentTableId',
                url: '${ctx}/pageJobLog',
                where: {'jobInfoId':jobInfoId},
                cols: [[
                    {field: 'jobGroupName', width: 150, title: '分组名', align: 'center'},
                    {field: 'title', width: 200, title: '任务名称', align: 'center'},
                    {field: 'executeStatus', width: 120, title: '执行状态', align: 'center'
                        ,templet:function(row){
                            if (row.executeStatus === 1) {
                                return '<span style="color: green;">成功</span>';
                            } else if (row.executeStatus === 0) {
                                return '<a style="color: red;cursor:pointer;" onclick="showFailMsg(\''+row.executeFailMsg+'\')">失败<i class="layui-icon">&nbsp;&#xe702;</i></a>';
                            } else {
                                return "-"
                            }
                        }
                    },
                    {field: 'createTime', width: 200, title: '执行时间', align: 'center'},
                    {field: 'executeParams', title: '执行参数', width: 250, align: 'center'},
                    {field: 'consumeTime', width: 120, title: '消耗时间', align: 'center'
                        ,templet:function(row){
                            if (row.consumeTime) {
                                return row.consumeTime + 'ms';
                            }
                        }
                    }
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                //res 即为原始返回的数据
                parseData: function(res) {
                    return {
                        "code": res.status == 200 ? 0 : -1, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.list //解析数据列表
                    };
                }
            });

            //监听单元格编辑
            table.on('edit(test)', function(obj) {
                var value = obj.value //得到修改后的值
                    ,
                    data = obj.data //得到所在行所有键值
                    ,
                    field = obj.field; //得到字段
                layer.msg('[ID: ' + data.id + '] ' + field + ' 字段更改为：' + value);
            });

            // 监听搜索操作
            form.on('submit(log-search-btn)', function (data) {
                //执行搜索重载
                table.reload('currentTableId', {
                    method: 'post'
                    , page: {
                        curr: 1
                    }
                    , where: {
                        queryStartTime: data.field.queryStartTime,
                        queryEndTime: data.field.queryEndTime
                    }
                });
                return false;
            });

        });

        // 展示错误原因
        function showFailMsg(msg) {
            msg = (!msg || msg == 'null') ? '' : msg;
            layer.open({
                type: 1
                ,title: '执行失败原因'
                ,offset: 'top'
                ,area: ['500px','250px']
                ,shade: 0.4
                ,content: '<div style="padding: 15px"><p>'+ msg +'</p></div>'
            });
        }

    </script>

</html>